package Midium;

//34.在排序数组中查找元素的第一个和最后一个位置
public class Solution34 {
    public int[] searchRange(int[] nums, int target) {
        //使用33题里写的find方法
        int tar = Solution33.find(nums, 0, nums.length - 1, target);
        int a = tar, b = tar;
        while (a > 0) {
            if (nums[--a] != target) {
                a++;
                break;
            }
        }
        while (b < nums.length - 1) {
            if (nums[++b] != target) {
                b--;
                break;
            }
        }
        return new int[]{a, b};
    }
}